package com.cssl.controller;

import cn.hutool.core.util.ObjectUtil;
import com.cssl.domain.DtsAddress;
import com.cssl.domain.dto.AddressDto;
import com.cssl.domain.dto.DtsAddressDto;
import com.cssl.service.DtsAddressService;
import com.cssl.util.InfoCode;
import com.cssl.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/useraddress")
@Api(value = "用户地址接口",tags = "用户地址相关操作")
public class DtsAddressController {

    @Autowired
    private DtsAddressService dtsAddressService;

    @PostMapping("/listAddress")
    public Result getAddressList(@RequestBody DtsAddressDto dtsAddressDto) {
        Map addressList = dtsAddressService.getAddressList(dtsAddressDto);
        if (ObjectUtil.isEmpty(addressList.get("list"))) {
            return Result.result(InfoCode.QUERY_EMPTY, InfoCode.MESSAGE_QUERY_EMPTY, null, System.currentTimeMillis());
        }
        return Result.result(InfoCode.OK, InfoCode.MESSAGE_OK, addressList, System.currentTimeMillis());
    }

    @PostMapping("/getUserAddress")
    @ApiOperation(value = "用户地址查询")
    public Result getUserAddress(){
        return dtsAddressService.getUserAddress();
    }

    @PostMapping("/getNationwide")
    @ApiOperation(value = "获得全国的省,市,县")
    public Result getNationwide(@RequestBody AddressDto address){
        return dtsAddressService.getNationwide(address);
    }

    @PostMapping("/getAllNationwide")
    @ApiOperation(value = "一次性获得全国的省,市,县")
    public Result getAllNationwide(){
        return dtsAddressService.getAllNationwide();
    }
    @PostMapping("/addUserAddress")
    @ApiOperation(value = "新增用户地址")
    public Result addUserAddress(@RequestBody DtsAddress address){
        return dtsAddressService.addUserAddress(address);
    }


    @PostMapping("/deleteUserAddress")
    @ApiOperation(value = "删除用户地址")
    public Result deleteUserAddress(@RequestBody DtsAddress address){
        return dtsAddressService.deleteUserAddress(address);
    }
}
